package com.itlong.cloud.property.resource;

import com.itlong.cloud.POJO.DTO.property.PropertyAddVisitorDTO;
import com.itlong.cloud.POJO.DTO.property.PropertyGetVisitorInfoDTO;
import com.itlong.cloud.POJO.PO.AppVisitorPassCodeRecordPO;
import com.itlong.cloud.POJO.VO.app.AppMineRoomInfoVO;
import com.itlong.cloud.POJO.VO.miniprogram.MiniProgramVisitorInfoVO;
import com.itlong.cloud.POJO.VO.property.PropertyGetVisitorInfoVO;
import com.itlong.cloud.POJO.VO.property.PropertyVisitorInfoByPushVO;
import com.itlong.cloud.POJO.VO.property.PropertyVisitorInfoVO;
import com.itlong.cloud.POJO.VO.property.PropertyVisitorSendMessageVO;
import com.itlong.cloud.property.service.IPropertyVisitorPassCodeRecordService;
import com.itlong.cloud.user.property.IPropertyVisitorServiceClient;
import com.itlong.cloud.utils.page.PageByVisitor;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RequestParam;
import org.springframework.web.bind.annotation.RestController;

import java.util.List;
import java.util.Map;

/**
 * <desc>
 *      物业-访客业务处理暴露接口实现类
 * </desc>
 *
 * @createDate 2018/06/28
 */
@RestController
public class PropertyVisitorServiceResource implements IPropertyVisitorServiceClient{
    @Autowired
    IPropertyVisitorPassCodeRecordService iPropertyVisitorPassCodeRecordService;
    /**
     * <desc>
     *      保存访客密码记录
     * </desc>
     *
     * @param propertyAddVisitorDTO 访客密码记录实体类
     * @return
     * @author Jiaqi.X
     * @createDate 2018/06/28
     */
    @Override
    @PostMapping(path = "/property/visitor/addVisitor")
    public AppVisitorPassCodeRecordPO addVisitor(@RequestBody PropertyAddVisitorDTO propertyAddVisitorDTO) throws Exception {
        return iPropertyVisitorPassCodeRecordService.save(propertyAddVisitorDTO);
    }

    /**
     * <desc>
     *     访客列表
     * <desc/>
     *
     *@param  visitorInfoDTO  分页查询访客列表
     * @return  MessageVO 标准格式化响应结果
     * @author JuGuang.S
     * @createDate 2018/06/28
     */
    @Override
    @PostMapping(path = "/property/visitor/getByPage")
    public PageByVisitor<PropertyVisitorInfoVO> getVisitorInfoByPage(@RequestBody PropertyGetVisitorInfoDTO visitorInfoDTO) throws Exception {
        return iPropertyVisitorPassCodeRecordService.getVisitorInfoByPage(visitorInfoDTO);
    }

    /**
     * <desc>
     *     根据访客ID获取访客信息
     * <desc/>
     *
     *@param  passId  访客ID
     * @return  PropertyGetVisitorInfoVO 访客信息VO
     * @author JuGuang.S
     * @createDate 2018/06/29
     */
    @Override
    @PostMapping(path = "/property/visitor/getVisitorInfo")
    public PropertyGetVisitorInfoVO getVisitorInfo(@RequestParam("passId")String passId) throws Exception {
        return iPropertyVisitorPassCodeRecordService.getVisitorInfo(passId);
    }

    /**
     * <desc>
     *     根据访客ID删除访客信息
     * <desc/>
     *
     *@param  projectId  项目编号
     *@param  visitorArr  访客ID多个以逗号分隔
     * @return
     * @author JuGuang.S
     * @createDate 2018/06/29
     */
    @Override
    @PostMapping(path = "/property/visitor/deleteVisitorInfo")
    public void deleteVisitorInfo(@RequestParam("projectId")String projectId, @RequestParam("visitorArr")String[] visitorArr) throws Exception {
        iPropertyVisitorPassCodeRecordService.deleteVisitorInfo(projectId,visitorArr);
    }

    /**
     * <desc>
     *     根据访客ID获取访客短信需要信息
     * <desc/>
     *
     *@param  passId
     * @return
     * @author JuGuang.S
     * @createDate 2018/06/29
     */
    @Override
    @PostMapping(path = "/property/visitor/getVisitorMessage")
    public PropertyVisitorSendMessageVO getVisitorMessage(@RequestParam("passId")String passId) throws Exception {
        return iPropertyVisitorPassCodeRecordService.getVisitorMessage(passId);
    }

    /**
     * <desc>
     *     根据访客ID更新发送短信的次数
     * <desc/>
     *
     *@param  passId  访客ID多个以逗号分隔
     * @return
     * @author JuGuang.S
     * @createDate 2018/07/02
     */
    @Override
    @PostMapping(path = "/property/visitor/updateSendMssCount")
    public void updateSendMssCount(@RequestParam("passId")String passId) throws Exception {
        iPropertyVisitorPassCodeRecordService.updateSendMssCount(passId);
    }

    /**
     * <desc>
     *     查询APP添加访客未向物业推送消息的访客信息
     * <desc/>
     *
     *@param
     * @return
     * @author JuGuang.S
     * @createDate 2018/07/04
     */
    @Override
    @PostMapping(path = "/property/visitor/getVisitorInfoByPush")
    public List<PropertyVisitorInfoByPushVO> getVisitorInfoByPush() throws Exception {
        return iPropertyVisitorPassCodeRecordService.getVisitorInfoByPush();
    }

    /**
     * <desc>
     *     向物业推送消息后需更新表中推送状态
     * <desc/>
     *
     *@param
     * @return
     * @author JuGuang.S
     * @createDate 2018/07/04
     */
    @Override
    @PostMapping(path = "/property/visitor/updatePushStatus")
    public void updatePushStatus(@RequestParam("passId")String[] passId) throws Exception {
        iPropertyVisitorPassCodeRecordService.updatePushStatus(passId);
    }

    /**
     * <desc>
     *     定时刷新访客表修改所有物业系统未在线时未推送消息的状态改为已推送，其定时刷新的时间须迟于VisitorPushMessageTimeTask.
     * <desc/>
     *
     *@param
     * @return
     * @author JuGuang.S
     * @createDate 2018/07/10
     */
    @Override
    @PostMapping(path = "/property/visitor/updateNotPushMessageStatus")
    public void updateNotPushMessageStatus() throws Exception {
        iPropertyVisitorPassCodeRecordService.updateNotPushMessageStatus();
    }

    /**
     * <desc>
     *      访客单审批
     * </desc>
     * @param passId 访客单ID
     * @param checkStatus 物业审核状态 1代表审批通过 2代表审批拒绝
     * @param type 1代表业主 2代表物业
     * @return
     * @author JuGuang.S
     * @createDate 2019/04/25
     */
    @Override
    @PostMapping(path = "/property/visitor/propertyCheckVisitor")
    public Integer propertyCheckVisitor(@RequestParam("passId") String passId,
                                        @RequestParam("checkStatus") Integer checkStatus,
                                        @RequestParam("loginUserId") String loginUserId,
                                        @RequestParam("type") Integer type) throws Exception {
        return iPropertyVisitorPassCodeRecordService.propertyCheckVisitor(passId,checkStatus,loginUserId,type);
    }

    /**
     * <desc>
     *     根据房屋编号模糊查询房间
     * <desc/>
     *
     *@param  unitId  单元编号
     *@param  roomNum  房间编号
     * @return  MessageVO 标准格式化响应结果
     * @author Qiang.S
     * @createDate 2019/05/14
     */
    @Override
    @PostMapping(path = "/property/visitor/getRoomInfoByNum")
    public List<AppMineRoomInfoVO> getRoomInfoByNum(@RequestParam("unitId") String unitId,
                                                    @RequestParam(value = "roomNum",required = false) String roomNum) {
        return iPropertyVisitorPassCodeRecordService.getRoomInfoByNum(unitId,roomNum);
    }

    /**
     * <desc>
     *      获取项目访客配置
     * </desc>
     *
     * @param projectId
     * @return
     * @author Jiaqi.X
     * @createDate 2020/05/22
     */
    @PostMapping(path = "/property/visitor/getVisitorConfigure")
    public Map<String,Object> getVisitorConfigure(@RequestParam("projectId") String projectId){
        return iPropertyVisitorPassCodeRecordService.getVisitorConfigure(projectId);
    }

    /**
     * <desc>
     *      根据passId获取访客具体数据
     * </desc>
     *
     * @param passId 访客单ID
     * @return
     * @author Juguang.S
     * @createDate 2020/01/13
     */
    @Override
    @PostMapping(path = "/property/visitor/getVisitorByRenewVisitor")
    public AppVisitorPassCodeRecordPO getVisitorByRenewVisitor(@RequestParam("passId") String passId) throws Exception{
        return iPropertyVisitorPassCodeRecordService.getVisitorByRenewVisitor(passId);
    }

    /**
     * <desc>
     *      重新访问注册人脸失败，则需将旧数据恢复
     * </desc>
     *
     * @param oldPO 旧访客数据
     * @return
     * @author Juguang.S
     * @createDate 2020/01/13
     */
    @Override
    @PostMapping(path = "/property/visitor/update")
    public void update(@RequestBody AppVisitorPassCodeRecordPO oldPO) throws Exception{
        iPropertyVisitorPassCodeRecordService.update(oldPO);
    }

    /**
     * <desc>
     *      获取访客时间限制信息
     * </desc>
     *
     * @param projectId 项目编号
     * @return
     * @author Juguang.S
     * @createDate 2020/09/15
     */
    @Override
    @PostMapping(path = "/property/visitor/getVisitorTimeInfo")
    public Map<String,Object> getVisitorTimeInfo(@RequestParam("projectId") String projectId) throws Exception{
        return iPropertyVisitorPassCodeRecordService.getVisitorTimeInfo(projectId);
    }

    /**
     * <desc>
     *      获取访客二维码内容
     * </desc>
     *
     * @param visitorId 访客id
     * @return
     * @Author Zhu.yj
     * @createDate  2021/6/2
     */

    @Override
    @PostMapping("/miniProgram/mine/getQRCodeContent")
    public MiniProgramVisitorInfoVO getQRCodeContent(@RequestParam("visitorId") String visitorId) throws Exception {
        return iPropertyVisitorPassCodeRecordService.getQRCodeContent(visitorId);
    }
}
